package com.cn.wanxi.servlet;

import com.cn.wanxi.dto.HomeModelDto;
import com.cn.wanxi.service.impl.HomeServiceImpl;
import com.cn.wanxi.service.IHomeService;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 网站首页
 */
@WebServlet("/frontHome")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.获取页面的值（查询首页 不需要传值）

//        2.将页面的值封装model（也不需要封装）
//        3.调用service
        IHomeService homeService = new HomeServiceImpl();
        HomeModelDto homeModelDto = homeService.getHomeModel();


//        4.返回页面(将得到的值返回给页面）
        JSONArray jsonArray = JSONArray.fromObject(homeModelDto);
        System.out.println(jsonArray.toString());
        resp.getWriter().println(jsonArray);
//        req.setAttribute("homeModel",homeModel);
//        req.getRequestDispatcher("/jsp/home.jsp").forward(req,resp);
    }
}
